package cn.itcast.mq.config;
import org.springframework.amqp.core.*;
import org.springframework.boot.autoconfigure.batch.BatchDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 作者:刘欢
 * @create 2024-02-27-14:09
 */
@Configuration
public class MessageConfig {

    /**
     * 创建队列
     * 用@Bean的方式创建一个队列
     */
//    @Bean
//    public Queue objectQueue() {
//        return new Queue("object.queue");
//    }

    /**
     * 定义topic类型交换机，命名为`pay.topic`
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("pay.topic");
    }

    /**
     * 定义消息队列，命名为`mark.order.pay.queue`
     */
    @Bean
    public Queue topicQueue1(){
        return new Queue("mark.order.pay.queue");
    }

    /**
     * 将`mark.order.pay.queue`与`pay.topic`绑定，`BindingKey`为`pay.success`
     */
    @Bean
    public Binding bindingTopicQueue1TopicExchange(Queue topicQueue1,TopicExchange topicExchange){
        return BindingBuilder.bind(topicQueue1).to(topicExchange).with("pay.success");
    }
}
